/*
 * Copyright (C) 2015 Daniel Uppenkamp
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.googlecode.maurersmarbles.drawables;

import com.google.common.base.Preconditions;
import com.googlecode.maurersmarbles.Rectangle;
import com.googlecode.maurersmarbles.ScreenCanvas;

/**
 *
 * @author Daniel Uppenkamp
 */
public class TextDrawable implements Drawable {

    /**
     * The color of the text.
     */
    protected int rgb;
    /**
     * The rectangle to draw the text in.
     */
    protected Rectangle rectangle;
    /**
     * The text to draw.
     */
    protected String text;

    /**
     * Creates a new TextDrawable.
     *
     * @param text the text to draw
     * @param rectangle the rectangle to draw the text in
     * @param rgb the color of the text
     */
    public TextDrawable(String text, Rectangle rectangle, int rgb) {

        Preconditions.checkNotNull(text, "Null text");
        Preconditions.checkNotNull(rectangle, "Null rectangle");

        this.text = text;
        this.rectangle = rectangle;
        this.rgb = rgb;

    }

    /**
     * Creates a new TextDrawable.
     *
     * @param text the text to draw
     * @param x the upper left x coordinate of the rectangle to draw the text in
     * @param y the upper left y coordinate of the rectangle to draw the text in
     * @param width the width of the rectangle to draw the text in
     * @param height the height of the rectangle to draw the text in
     * @param rgb the color of the text
     */
    public TextDrawable(String text, int x, int y, int width, int height, int rgb) {
        this(text, new Rectangle(x, y, width, height), rgb);
    }

    @Override
    public void draw(ScreenCanvas screenCanvas) {

        Preconditions.checkNotNull(screenCanvas, "Null screen canvas");

        if (text != null) {
            screenCanvas.drawStringCentered(text, rectangle, rgb);
        }

    }

}
